<div id="templatemo_upcomming_event" class="container_wapper">
    <div class="container">
        <?php
        if ($detil_kontak == null) {
            echo '<h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------Data Kontak Tidak Ditemukan-------------------</h1>';
        } else {
            foreach ($detil_kontak as $data) {
                ?>
                <h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------Edit Kontak-------------------</h1>
                <input type="hidden" value="<?= $data->id_kontak; ?>" id="id_kontak"/>
                <table id="table-content">                
                    <tr>
                        <td align="left">Nama Kontak</td>
                        <td>:</td>                                            
                        <td><input type="text" id="nama_kontak" value="<?= $data->nama_kontak; ?>"/></td> 
                    </tr>
                    <tr>
                        <td align="left">No. HP</td>
                        <td>:</td>                                            
                        <td><input type="text" id="notelp_kontak" value="<?= $data->notelp_kontak; ?>"/></td> 
                    </tr>
                    <tr>
                        <td align="left">Group</td>
                        <td>:</td>                                            
                        <td><input type="text" id="group" value="<?= $data->group_kontak; ?>"/></td> 
                    </tr>
                    <tr>
                        <td align="left">Keterangan</td>
                        <td>:</td>                                            
                        <td><input type="text" id="keterangan" value="<?= $data->keterangan; ?>"/></td> 
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td><input type="button" id="update_profil" name="update_profil" class="button_blue" value="Update"></td>
                    </tr>
                </table>
                <?php
            }
        }
        ?>
    </div>
</div>
<script>
    $(function() {
        $("#update_profil").click(function(event) {
            var id_kontak = document.getElementById('id_kontak').value;
            var nama_kontak = document.getElementById('nama_kontak').value;
            var notelp_kontak = document.getElementById('notelp_kontak').value;
            var group = document.getElementById('group').value;
            var keterangan = document.getElementById('keterangan').value;

            if (nama_kontak == "" || notelp_kontak == "") {
                show_alert("Nama atau No. HP tidak boleh kosong");
            } else {
                show_dialog("Silahkan tunggu, transaksi anda sedang kami proses...");
                $.ajax({
                    url: '<?php echo base_url(); ?>index.php/pesan/kontak_edit',
                    type: "POST",
                    timeout: 30000,
                    data: {
                        id_kontak: id_kontak,
                        nama_kontak: nama_kontak,
                        notelp_kontak: notelp_kontak,
                        group: group,
                        keterangan: keterangan,
                        '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
                    },
                    success: function(result)
                    {
                        var obres = $.parseJSON(result);
                        var err_code = obres.err_code;

                        if (err_code !== "00") {
                            hide_dialog(obres.msg);
                        }
                        else
                        {
                            hide_dialog("");
                            alert(obres.msg);
                            location.href = "<?=site_url("/pesan/pesan_masuk/")?>";
                        }
                    },
                    error: function()
                    {
                        hide_dialog("Terdapat masalah dengan koneksi internet anda, silahkan coba kembali.");
                    }
                });
            }
        });
    });
</script>
</body>
</html>